#include "config.h"
#include "gtkapplicationprivate.h"
+#include "gtkbuilder.h"
#import <Cocoa/Cocoa.h>
typedef struct
}
@end
+/* these exist only for accel handling */
+static void
+gtk_application_impl_quartz_hide (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ [NSApp hide:NSApp];
+}
+
+static void
+gtk_application_impl_quartz_hide_others (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ [NSApp hideOtherApplications:NSApp];
+}
+
+static void
+gtk_application_impl_quartz_show_all (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ [NSApp unhideAllApplications:NSApp];
+}
+
+static GActionEntry gtk_application_impl_quartz_actions[] = {
+ { "hide", gtk_application_impl_quartz_hide },
+ { "hide-others", gtk_application_impl_quartz_hide_others },
+ { "show-all", gtk_application_impl_quartz_show_all }
+};
+
static void
gtk_application_impl_quartz_startup (GtkApplicationImpl *impl,
gboolean register_session)
{
GtkApplicationImplQuartz *quartz = (GtkApplicationImplQuartz *) impl;
+ GSimpleActionGroup *gtkinternal;
+ GMenuModel *app_menu;
if (register_session)
{
quartz->muxer = gtk_action_muxer_new ();
gtk_action_muxer_set_parent (quartz->muxer, gtk_application_get_action_muxer (impl->application));
- /* app menu must come first so that we always see index '0' in
- * 'combined' as being the app menu.
- */
- gtk_application_impl_set_app_menu (impl, gtk_application_get_app_menu (impl->application));
+ /* Add the default accels */
+ gtk_application_add_accelerator (impl->application, "<Primary>comma", "app.preferences", NULL);
+ gtk_application_add_accelerator (impl->application, "<Primary><Alt>h", "gtkinternal.hide-others", NULL);
+ gtk_application_add_accelerator (impl->application, "<Primary>h", "gtkinternal.hide", NULL);
+ gtk_application_add_accelerator (impl->application, "<Primary>q", "app.quit", NULL);
+
+ /* and put code behind the 'special' accels */
+ gtkinternal = g_simple_action_group_new ();
+ g_action_map_add_action_entries (G_ACTION_MAP (gtkinternal), gtk_application_impl_quartz_actions,
+ G_N_ELEMENTS (gtk_application_impl_quartz_actions), quartz);
+ gtk_application_insert_action_group (impl->application, "gtkinternal", G_ACTION_GROUP (gtkinternal));
+ g_object_unref (gtkinternal);
+
+ /* now setup the menu */
+ app_menu = gtk_application_get_app_menu (impl->application);
+ if (app_menu == NULL)
+ {
+ GtkBuilder *builder;
+
+ /* If the user didn't fill in their own menu yet, add ours.
+ *
+ * The fact that we do this here ensures that we will always have the
+ * app menu at index 0 in 'combined'.
+ */
+ builder = gtk_builder_new_from_resource ("/org/gtk/libgtk/gtkapplication-quartz.ui");
+ gtk_application_set_app_menu (impl->application, G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu")));
+ g_object_unref (builder);
+ }
+ else
+ gtk_application_impl_set_app_menu (impl, app_menu);
+
+ /* This may or may not add an item to 'combined' */
gtk_application_impl_set_menubar (impl, gtk_application_get_menubar (impl->application));
/* OK. Now put it in the menu. */
--- /dev/null
+<interface>
+ <menu id='app-menu'>
+ <section>
+ <item>
+ <!-- used for the application menu on MacOS. %s is replaced with the application name. -->
+ <attribute name='label' translatable='yes'>About %s</attribute>
+ <attribute name='action'>app.about</attribute>
+ <attribute name='x-gtk-private-special'>replace-appname</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <!-- used for the application menu on MacOS -->
+ <attribute name='label' translatable='yes'>Preferences</attribute>
+ <attribute name='action'>app.preferences</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <!-- used for the application menu on MacOS -->
+ <attribute name='label' translatable='yes'>Services</attribute>
+ <attribute name='x-gtk-private-special'>services-submenu</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <!-- used for the application menu on MacOS. %s is replaced with the application name. -->
+ <attribute name='label' translatable='yes'>Hide %s</attribute>
+ <attribute name='x-gtk-private-special'>hide-this</attribute>
+ <attribute name='action'>gtkinternal.hide</attribute>
+ </item>
+ <item>
+ <!-- used for the application menu on MacOS -->
+ <attribute name='label' translatable='yes'>Hide Others</attribute>
+ <attribute name='x-gtk-private-special'>hide-others</attribute>
+ <attribute name='action'>gtkinternal.hide-others</attribute>
+ </item>
+ <item>
+ <!-- used for the application menu on MacOS -->
+ <attribute name='label' translatable='yes'>Show All</attribute>
+ <attribute name='x-gtk-private-special'>show-all</attribute>
+ <attribute name='action'>gtkinternal.show-all</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <!-- used for the application menu on MacOS. %s is replaced with the application name. -->
+ <attribute name='label' translatable='yes'>Quit %s</attribute>
+ <attribute name='action'>app.quit</attribute>
+ <attribute name='x-gtk-private-special'>replace-appname</attribute>
+ </item>
+ </section>
+ </menu>
+</interface>